package com.milestone.fitnesspersonaltrainer.repository.imp;


import com.milestone.fitnesspersonaltrainer.model.CategoryModel;
import com.milestone.fitnesspersonaltrainer.model.HomeModel;
import com.milestone.fitnesspersonaltrainer.network.RetrofitBuilder;
import com.milestone.fitnesspersonaltrainer.network.response.RxVoid;
import com.milestone.fitnesspersonaltrainer.network.rx.BaseResponseFunc1;
import com.milestone.fitnesspersonaltrainer.repository.api.WallpaperRepo;
import com.milestone.fitnesspersonaltrainer.service.WallpaperService;

import org.androidannotations.annotations.AfterInject;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;

import java.util.ArrayList;

import io.reactivex.Flowable;

/**
 * Created by ThinkPad on 2017/11/2.
 */
@EBean(scope = EBean.Scope.Singleton)
public class WallpaperRepoImp implements WallpaperRepo {

    @Bean
    RetrofitBuilder mRetrofitBuilder;
    private WallpaperService wallpaperService;

    @AfterInject
    void initService() {
        wallpaperService = mRetrofitBuilder.build().create(WallpaperService.class);
    }

    @Override
    public Flowable <ArrayList<HomeModel>> getGallery() {
        return wallpaperService.getGalleryData().flatMap(new BaseResponseFunc1<ArrayList<HomeModel>>());
    }

    @Override
    public Flowable <ArrayList<HomeModel>> getHome(int pageIndex, int pageCount, int categoryLimit) {
        return wallpaperService.getHomeData(pageIndex, pageCount, categoryLimit).flatMap(new BaseResponseFunc1<ArrayList<HomeModel>>());
    }

    @Override
    public Flowable <ArrayList<CategoryModel>> getCategory() {
        return wallpaperService.getCategoryData().flatMap(new BaseResponseFunc1<ArrayList<CategoryModel>>());
    }

    @Override
    public Flowable <ArrayList<HomeModel>> getPicByCateory(int pageIndex, int pageCount, String category) {
        return wallpaperService.getPicturesByCategory(pageIndex, pageCount, category).flatMap(new BaseResponseFunc1<ArrayList<HomeModel>>());
    }

    @Override
    public Flowable <ArrayList<HomeModel>> getPicBySearch(int pageCount, String keyWords) {
        return wallpaperService.searchPicture(pageCount, keyWords).flatMap(new BaseResponseFunc1<ArrayList<HomeModel>>());
    }

    @Override
    public Flowable <RxVoid> addLike(String url) {
        return wallpaperService.addLike(url).flatMap(new BaseResponseFunc1<RxVoid>());
    }
}
